package com.ocean.greedy;

import com.ocean.TreeNode;

/**
 * <Description> <br>
 *
 * @author linmiaolai@sanyygp.com<br>
 * @version 1.0<br>
 * @date 2023/02/24 <br>
 */
public class TreeNodeOperator {
    private TreeNode root;

    public TreeNode getRoot() {
        return root;
    }

    public TreeNode add(int val) {
        if (root == null) {
            root = new TreeNode(val, null, null);
            return root;
        }
        // 遍历
        TreeNode temp = root;
        while (temp != null) {
            if (temp.val > val) {
                if (temp.left == null) {
                    temp.left = new TreeNode(val);
                    break;
                }
                temp = temp.left;
            } else {
                if (temp.right == null) {
                    temp.right = new TreeNode(val);
                    break;
                }
                temp = temp.right;
            }
        }
        return root;
    }
}
